//
//  UIButton+Extension.swift
//  MattressTool
//
//  Created by Coder Yang on 2023/11/22.
//

import UIKit

extension UIButton {
    
    convenience init(title: String?,
                     font: UIFont = .body,
                     color: UIColor = .white,
                     backgroundColor: UIColor? = nil) {
        self.init()
        
        setTitle(title, for: .normal)
        setTitleColor(color, for: .normal)
        titleLabel?.font = font
        
        if nil != backgroundColor {
            self.backgroundColor = backgroundColor
        }
        
        sizeToFit()
    }
    
    convenience init(normal: UIImage?,
                     selected: UIImage?) {
        self.init()
    
        setImage(normal, for: .normal)
        setImage(selected, for: .selected)
        
        sizeToFit()
    }
    
    convenience init(normalTitle: String,
                     selectedTitle: String,
                     normal: UIImage? = nil,
                     selected: UIImage? = nil) {
        self.init()
    
        setTitle(normalTitle, for: .normal)
        setTitle(selectedTitle, for: .selected)
        setImage(normal, for: .normal)
        setImage(selected, for: .selected)
        
        sizeToFit()
    }
}
